import request from "@/utils/request";
import type {
  spuRecordsList,
  getspuListts,
  getBrandListArray,
  SalesAttributeArray,
  SaveOrUpdateSpuApiParams,
  SpuSaleAttrItem,
} from "./model/spu";

enum Api {
  GetpaginationspuList = "/admin/product",
  GetBrandList = "/admin/product/baseTrademark/getTrademarkList",
  GetSalesAttribute = "/admin/product/baseSaleAttrList",
  saveSpuUrl = "/admin/product/saveSpuInfo",
  getSpuImageListUrl = "/admin/product/spuImageList",
  getSpuSaleAttrListUrl = "/admin/product/spuSaleAttrList",
  updateSpuUrl = "/admin/product/updateSpuInfo",
}

// { page: number, limit: number, category3Id: number }
// const obj = {
//   page: currentPage.value,
//   limit: pageSize.value,
//   category3Id: CategoryStore.category3Id
// }
//

/**
 *
 * @param 传进来是是一个对象 对象有 1.当前页数  2.一页多个条数据   3.3级id的id
 * @returns
 */
export const getPaginationspuList = ({
  page,
  limit,
  category3Id,
}: getspuListts) => {
  return request.get<any, spuRecordsList>(
    Api.GetpaginationspuList + `/${page}/${limit}?category3Id=${category3Id}`
  );
  // return request.get<any, spuRecordsList>(Api.getpaginationspuList + `/1/5?category3Id=1`,);
};

/**
 *
 * @returns 一个数据 ts 类型  getBrandListArray
 */
// 发送获取添加 和 修改 功能的 品牌属性
export const getBrandList = () => {
  return request.get<any, getBrandListArray>(Api.GetBrandList);
};

/**
 *
 * @returns 一个数组  类型是
 */

// 发送获取添加 和 修改 功能的 销售属性
export const getSalesAttribute = () => {
  return request.get<any, SalesAttributeArray>(Api.GetSalesAttribute);
};

/**
 * 添加Spu
 * @param data SaveOrUpdateSpuApiParams
 * @returns null
 */
export const saveSpuApi = (data: SaveOrUpdateSpuApiParams) => {
  return request.post<any, null>(Api.saveSpuUrl, data);
};

/**
 * 根据id获取销售属性列表
 * @param id spu的id
 * @returns SpuSaleAttrList
 */
export const getSpuSaleAttrListApi = (id: number) => {
  return request.get<any, any>(Api.getSpuSaleAttrListUrl + `/${id}`);
};

/**
 * 根据id获取图片列表
 * @param id spu的id
 * @returns SpuImageList
 */
export const getSpuImageListApi = (id: number) => {
  return request.get<any, any>(Api.getSpuImageListUrl + `/${id}`);
};

/**
 * 更新SPU`
 * @param data SaveOrUpdateSpuApiParams
 * @returns null
 */
export const updateSpuApi = (data: SaveOrUpdateSpuApiParams) => {
  console.log(data);
  return request.post<any, null>(Api.updateSpuUrl, data);
};
